<?php
defined( '_VALID_MOS' ) or die( 'Restricted access' );
class HTML_content {	
	//List products
	function showListProduct( &$title, &$total, &$rows, &$pageNav, &$link_page, &$numberPage, &$row ){
	global $mosConfig_live_site, $my;
	$imageurl 	= $mosConfig_live_site."/uploads/content";
	$task		= mosGetParam($_REQUEST, 'task', '');
	?>
	<div class="w_title_website title-css3">
		<div class="w_show_title_website">Tin <?php echo $title;?> mới nhất</div>
		<div class="clearfix"></div>
		<div class="w_show_content">
			<?php
			if ($total==0){
			?>
			<p style="text-align:center; color:red; line-height:30px;">
			Không tìm thấy sản phẩm nào trong danh mục này !
			</p>
			<?php }else{?>
			<table class="w_showTable" width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td width="30">Ảnh</td>
						<td width="400">Tên sản phẩm</td>
						<td>Thể loại</td>
						<td>Ngày đăng</td>
						<td>Nơi đăng</td>
					</tr>	
				</thead>
				<tbody>
					<?php
					for ($i=0; $i<count($rows); $i++){
					$link = sefRelToAbs("index.php?option=com_content&task=view&catid=".$rows[$i]->catid."&id=".$rows[$i]->id).$rows[$i]->title_alias.".html";
					if ($task == 'blogsection')	{
						$linkCat = sefRelToAbs("index.php?option=com_content&task=blogsection&id=".$rows[$i]->sectionid).$rows[$i]->html_secname.".html";
					}else{
						$linkCat = sefRelToAbs("index.php?option=com_content&task=blogcategory&id=".$rows[$i]->catid).$rows[$i]->html_namecat.".html";
					}	
					?>
					<tr>
						<td>
							<a href="<?php echo $link;?>" title="<?php echo $rows[$i]->title;?>">
							<?php if($rows[$i]->thumbnailImage!=''){?>
							<img src="<?php echo $imageurl;?>/thumbnail/<?php echo $rows[$i]->thumbnailImage;?>" width="20" border="0" />
							<?php }else{?>
							<img src="<?php echo $mosConfig_live_site;?>/templates/html_ngayhomnay/images/nopic.gif" width="20" border="0" />
							<?php }?>
							</a>
						</td>
						<td><a href="<?php echo $link;?>" title="<?php echo $rows[$i]->title;?>"><?php echo $rows[$i]->title;?></a></td>
						<?php if ($task == 'blogsection'){?>
						<td><a href="<?php echo $linkCat;?>"><?php echo $rows[$i]->title_sec;?></a></td>
						<?php }else{ ?>
						<td><a href="<?php echo $linkCat;?>"><?php echo $rows[$i]->titlecat;?></a></td>
						<?php }?>
						<td><?php echo unFormatDate($rows[$i]->created, "d/m/Y");?></td>
						<td>Hà Nội</td>
					</tr>
					<?php
					}
					?>
				</tbody>
				<tfoot>
				</tfoot>
			</table>
			<?php }?>
		</div>
	</div>
	<?php
		if($total>$numberPage){
			?>
			<div class="page">
			<?php
			echo $pageNav->writePagesLinks( $link_page );
			?>
			</div>
			<?php
		}
	}
	
	//Function Detail Product
	function viewDisplayProduct(&$row, &$total, &$rows, &$pageNav, &$link_page, &$numberPage, &$hangsx, &$totalhangsx, &$linkhangsx ){
	global $mosConfig_live_site, $database;
	$url = $mosConfig_live_site."/administrator/components/com_content/uploads/";
	mysql_query('update jos_content set view='.($row->view+1).' where id='.$row->id);
	?>
		<div class="title_main"><span>Chi tiết sản phẩm</span></div>
		<table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
			<tr>
				<td valign="top" style="padding:3px; padding-right:0; vertical-align:top;">
					<div id="productImageWrapID_<?php echo $row->id;?>">
						<?php
						if ($row->img2!=''){
							echo '<img src="'.$url.$row->img2.'" width="250" border="0" style="float:left; margin:0 8px 0 0;" />';
						}else if ($row->img!=''){
							echo '<img src="'.$url.$row->img.'" width="250" border="0" style="float:left; margin:0 8px 0 0;" />';
						}else{
							echo '<img src="'.$url.'no_pic.gif" width="250" border="0" style="float:left; margin:0 8px 0 0;" />';
						}
						?>
					</div>
					</td>
					<td valign="top" style="padding-left:7px; vertical-align:top;">
					<div class="field_detail"><h3><?php echo $row->title;?></h3></div>
					<?php
					if ($row->price_niem_yet>0){
						echo '<div class="field_detail_price_ny">';
							echo 'Giá niêm yết: '.number_format($row->price_niem_yet,0,',','.').' VNĐ';
						echo '</div>';
					}
					if ($row->price_giam>0){
						echo '<div class="field_detail_price_ny">';
							echo 'Giá bán: <b style="color:red;">'.number_format($row->price,0,',','.').' VNĐ</b>';
							if($row->don_vi!=''){
								echo ' /<b> '.$row->don_vi.'</b>';
							}
						echo '</div>';
					}else{
						echo '<div class="field_detail">';
							echo 'Giá bán: <b style="color:red;">'.number_format($row->price,0,',','.').' VNĐ</b>';
							if($row->don_vi!=''){
								echo ' /<b> '.$row->don_vi.'</b>';
							}
						echo '</div>';
					}
					if ($row->price_giam>0){
						echo '<div class="field_detail">';
							echo 'Giá giảm: <b style="color:red;">'.number_format($row->price_giam,0,',','.').' VNĐ</b>';
							if($row->don_vi!=''){
								echo ' /<b> '.$row->don_vi.'</b>';
							}
							echo ' <i>(Giảm :'.$row->giam_gia.'%)</i>';
						echo '</div>';
					}
					if ($row->bao_hanh!=''){
						echo '<div class="field_detail">';
							echo 'Bảo hành: <b>'.$row->bao_hanh.'</b>';
						echo '</div>';
					}
					echo '<div class="field_detail">';
						echo 'Số lượt xem: <b>'.number_format($row->view,0,',','.').'</b>';
					echo '</div>';
					echo '<div class="field_detail">';
						echo 'Ngày đưa lên: <b>'.unFormatDate($row->created,"d/m/Y").'</b>';
					echo '</div>';
					if ($row->saleoff==1){
						echo '<div class="field_detail" style="background:#B7FFFC; color:red;">';
							echo '<b>Đang khuyến mại</b>';
						echo '</div>';
						if ($row->promotional1!=''){
							echo '<div class="field_detail">';
								echo '[1]. '.$row->promotional1;
							echo '</div>';
						}
						if ($row->promotional2!=''){
							echo '<div class="field_detail">';
								echo '[2]. '.$row->promotional2;
							echo '</div>';
						}
						if ($row->promotional3!=''){
							echo '<div class="field_detail">';
								echo '[3]. '.$row->promotional3;
							echo '</div>';
						}
						if ($row->promotional4!=''){
							echo '<div class="field_detail">';
								echo '[4]. '.$row->promotional4;
							echo '</div>';
						}
						if ($row->promotional5!=''){
							echo '<div class="field_detail">';
								echo '[5]. '.$row->promotional5;
							echo '</div>';
						}
					}
					if ($row->status==1){
						echo '<div class="field_detail" style="background:#B7FFFC; color:#002A8B;">';
							echo 'Tình trạng : <b>Còn hàng</b>';
						echo '</div>';
					}else if ($row->status==2){
						echo '<div class="field_detail" style="background:#B7FFFC; color:#620001;">';
							echo 'Tình trạng : <b>Chưa có hàng</b>';
						echo '</div>';
					}else{
						echo '<div class="field_detail" style="background:#B7FFFC; color:red;">';
							echo 'Tình trạng : <b>Hết hàng</b>';
						echo '</div>';
					}
					?>
					<div class="field_detail">
						Hãng sản xuất : <a href="<?php echo $linkhangsx;?>"><?php echo $hangsx->name;?></a> (<?php echo $totalhangsx;?>)
					</div>
				</td>
			</tr>
			<tr>
				<td align="center">
					<?php if ($row->status==1){?>
					<a id="ajax<?php echo $row->id;?>">
						<img src="<?php echo $mosConfig_live_site;?>/templates/maxco/images/cart.jpg" border="0" id="featuredProduct_<?php echo $row->id;?>" />
					</a>
					&nbsp;&nbsp;
					<a href="<?php echo sefRelToAbs("index.php?option=com_orderonline&task=view");?>">
					<img src="<?php echo $mosConfig_live_site;?>/templates/maxco/images/order.gif" border="0" />
					</a>
					<?php }?>
				</td>
				<td></td>
			</tr>
			<tr><td colspan="2" style="line-height:18px; padding-top:10px;"><?php echo $row->fulltext;?></td></tr>
		</table>
		<script type="text/javascript">
		$(function() {
			$('#ajax<?php echo $row->id;?>').click(function() {
				$('#gio_hang').load('<?php echo $mosConfig_live_site;?>/ajax/orderonline.php?id=<?php echo $row->id;?>');
			});
		});
		</script>
		<div class="title_main"><span>Sản phẩm cùng loại</span></div>
		<?php
		$url = $mosConfig_live_site."/administrator/components/com_content/uploads/";
		for ($i=0; $i<count($rows); $i++){
		$link = sefRelToAbs("index.php?option=com_content&task=view&catid=".$rows[$i]->catid."&id=".$rows[$i]->id).$rows[$i]->title_alias.".html";
		?>
		<div class="boxproduct">
			<div class="image" id="productImageWrapID_<?php echo $rows[$i]->id;?>">
				<?php
				if ($rows[$i]->img!=''){
				?>
				<a href="<?php echo $link;?>"><img src="<?php echo $url.$rows[$i]->img;?>" /></a>
				<?php
				}else{
				?>
				<a href="<?php echo $link;?>"><img src="<?php echo $url;?>no_pic.gif" /></a>
				<?php
				}
				?>
			</div>
			<div class="field"><a href="<?php echo $link;?>"><?php echo $rows[$i]->title;?></a></div>
			<div class="price">Giá : <?php echo number_format($rows[$i]->price,0,',','.');?> VNĐ</div>
			<div class="field">
				<?php if ($rows[$i]->status==1){?>
				<div class="cart">
					<a id="ajax<?php echo $rows[$i]->id;?>">
						<img src="<?php echo $mosConfig_live_site;?>/templates/maxco/images/cart.jpg" border="0" id="featuredProduct_<?php echo $rows[$i]->id;?>" />
					</a>
				</div>
				<?php }else if ($rows[$i]->status==2){?>
				<div class="cart" style="color:#ff7700;">Chưa có hàng</div>
				<?php }else{?>
				<div class="cart" style="color:red;">Hết hàng</div>
				<?php }?>
				<div class="detail"><a href="<?php echo $link;?>">Chi tiết</a></div>
			</div>
		</div>
		<?php
		}
		?>
		<script type="text/javascript">
		$(function() {
			<?php 
			for ($i=0; $i<count($rows); $i++){
			?>
			$('#ajax<?php echo $rows[$i]->id;?>').click(function() {
				$('#gio_hang').load('<?php echo $mosConfig_live_site;?>/ajax/orderonline.php?id=<?php echo $rows[$i]->id;?>');
			});
			<?php }?>
		});
		</script>
		<?php
		if($total>$numberPage){
			?>
			<div class="page">
			<?php
			echo $pageNav->writePagesLinks( $link_page );
			?>
			</div>
			<?php
		}
	}
	
	//showList News
	function showListNews( &$total, &$rows, &$pageNav, &$link_page, &$numberPage, &$row ){
	global $mosConfig_live_site;
	$url = $mosConfig_live_site."/administrator/components/com_content/uploads/";
	?>
		<div class="title_main"><span><?php echo $row->title;?></span></div>
		<?php
		for ($i=0; $i<count($rows); $i++){
		$link = sefRelToAbs("index.php?option=com_content&task=view&catid=".$rows[$i]->catid."&id=".$rows[$i]->id).$rows[$i]->title_alias.".html";
		?>
		<div class="lsNews">
			<a href="<?php echo $link;?>"><img src="<?php echo $url.$rows[$i]->img;?>" /></a>
			<p><a href="<?php echo $link;?>"><?php echo $rows[$i]->title;?></a></p>
			<?php echo mb_substr($rows[$i]->introtext,0,500,"utf-8")."...";?>
			<p align="right"><a href="<?php echo $link;?>" class="chi_tiet">Xem tiết...</a></p>
		</div>
		<?php
		}
		if($total>$numberPage){
			?>
			<div class="page">
			<?php
			echo $pageNav->writePagesLinks( $link_page );
			?>
			</div>
			<?php
		}
	}
	
	//Function view News
	function viewDisplayNews( &$row, &$total, &$rows, &$pageNav, &$link_page, &$numberPage ){
	global $mosConfig_live_site, $database;
	$url = $mosConfig_live_site."/administrator/components/com_content/uploads/";
	?>
		<div class="title_main"><span>Chi tiết bài viết</span></div>
		<div class="lsNews">
			<?php
			if ($row->img2==''){
			?>
			<img src="<?php echo $url.$row->img;?>" border="0" width="150" />
			<?php
			}else{
			?>
			<img src="<?php echo $url.$row->img2;?>" border="0" width="250" />
			<?php
			}
			?>
			<p><h3><?php echo $row->title;?></h3></p>
			<p class="datetime">(<?php echo unFormatDate($row->created,"d/m/Y");?>)</p>
			<p class="description"><?php echo $row->introtext;?></p>
			<p><?php echo $row->fulltext;?></p>
			<p>
				<ul> Các bài viết khác
					<?php
					$url = $mosConfig_live_site."/administrator/components/com_content/uploads/";
					for ($i=0; $i<count($rows); $i++){
					$link = sefRelToAbs("index.php?option=com_content&task=view&catid=".$rows[$i]->catid."&id=".$rows[$i]->id).$rows[$i]->title_alias.".html";
					?>
						<li><a href="<?php echo $link;?>"><?php echo $rows[$i]->title;?></a></li>
					<?php
					}
					?>
				</ul>
		</p>
		</div>
	<?php
	}

	//Tải báo giá
	function downloadQuotes( &$lsCategories ){
		global $database, $mosConfig_live_site;
		?>
		<div class="title_main"><span>Tải báo giá</span></div>
		<table width="100%" style="margin:0;" cellpadding="0" cellspacing="0" class="border">
			<tr>
				<td align="center" valign="top" bgcolor="#EEEDE9"><b>STT</b></td>
				<td align="center" valign="top" bgcolor="#EEEDE9"><b>NHÓM SẢN PHẨM</b></td>
				<td align="center" valign="top" bgcolor="#EEEDE9"><b>NGÀY CẬP NHẬT</b></td>
				<td align="center" valign="top" bgcolor="#EEEDE9"><b>BÁO GIÁ</b></td>
			</tr>
			<?php 
					for ($i=0; $i<count($lsCategories); $i++){
//						$linkdown = $mosConfig_live_site."/administrator/components/com_categories/uploads/".$lsCategories[$i]->download;
						$linkdown = "index.php?option=com_content&task=save&catid=".$lsCategories[$i]->id;
						$sql = "SELECT * FROM #__categories WHERE section=1 AND published=1 AND parent_id=".$lsCategories[$i]->id." ORDER BY ordering ASC, id DESC";
						$database->setQuery($sql);
						$lsParent = $database->loadOBjectList();
					?>
			<tr>
				<td><b><?php echo $i+1;?></b></td>
				<td><b><?php echo $lsCategories[$i]->title;?></b></td>
				<!--<td><?php echo date("d/m/Y");?></td>-->
				<td><?php echo unFormatDate($lsCategories[$i]->created,"d/m/Y");?></td>
				<?php if ($lsCategories[$i]->download!=''){?>
				<td><a href="<?php echo $linkdown;?>" style="color:#006699; font-weight: normal;">Tải báo giá</a></td>
				<?php }else{?>
				<td align="center"><a href="<?php echo $linkdown;?>" style="color:#006699; font-weight: bold;">Tải báo giá</a></td>
				<?php }?>
			</tr>
			<?php
				for ($j=0; $j<count($lsParent); $j++){
					$linkdown2 = "index.php?option=com_content&task=save&catid=".$lsParent[$j]->id;
					?>
					<tr>
						<td></b></td>
						<td>--- <?php echo $lsParent[$j]->title;?></td>
						<td><?php echo date("d/m/Y");?></td>
						<td><a href="<?php echo $linkdown2;?>" style="color:#006699; font-weight: normal;">Tải báo giá</a></td>
					</tr>
					<?php
				} 
			}
			?>
		</table>
		<?php
	}
}
?>